package com.sgb.kjwl.view.ui.adapter.transport;

import android.content.Context;
import android.graphics.Paint;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.GasListInfoEntity;
import com.sgb.kjwl.model.entity.GasStationInfoEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.math.BigDecimal;
import java.util.List;

public class GasListAdapter extends BaseRecycleAdapter<GasListInfoEntity> {
    public GasListAdapter(Context context,  List<GasListInfoEntity> datas) {
        super(context, R.layout.item_gas_list, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, GasListInfoEntity infoEntity) {
        holder.setBinding(BR.viewModel, infoEntity);
        TextView tvFree=holder.itemView.findViewById(R.id.tv_free);
        TextView tvDistance=holder.itemView.findViewById(R.id.tv_distance);
        TextView tvPice=holder.itemView.findViewById(R.id.tv_price2);
        TextView tvPice1=holder.itemView.findViewById(R.id.tv_price);
        if(!TextUtils.isEmpty(infoEntity.getFavouredPolicy())){
            tvFree.setVisibility(View.VISIBLE);
            tvFree.setText(infoEntity.getFavouredPolicy());
        }else{
            tvFree.setVisibility(View.GONE);

        }
        tvDistance.setText(m1(Double.valueOf(infoEntity.getDistance())/1000)+"km");
        tvPice.setText("标准价¥"+infoEntity.getStandardPrice());
        tvPice1.setText("¥"+infoEntity.getPrice());
        tvPice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);


    }
    /**
     * BigDecimal转double 四舍五入保留两位小数
     */
    public double m1(double num) {
        BigDecimal bg = new BigDecimal(num);
        double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return f1;
    }
}
